package com.tyc.server.controller;

import com.tyc.server.service.Server02Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: java类作用描述
 * @Author: tyc
 * @CreateDate: 2021/2/4 14:02
 */
@RestController
@RequestMapping("s8001")
@RefreshScope
public class TestController {
//    @Autowired
//    private Server02Service server02Service;
//
//    @Value("${test.name}")
//    private String name;
//
//    @GetMapping()
//    public String getName(){
//        return name;
//    }
//
//    @GetMapping("/02")
//    public String getServer02(){
//        return server02Service.getName();
//    }
//    @PostMapping()
//    public String tets(){
//        return "success";
//    }

//    @PostMapping
    //public OrderInfo create(@RequestBody OrderInfo info, @AuthenticationPrincipal User user){
//    public OrderInfo create(@RequestBody OrderInfo info, @AuthenticationPrincipal(expression = "#this.id") Long id){
        //log.info("获取到username = {}",user.getUsername());
//        log.info("获取到id  = {}",id);
        //查询价格
//        PriceInfo price = restTemplate.getForObject("http://localhost:9080/prices/"+info.getProductId(),PriceInfo.class);
//        log.info("price is "+price.getPrice());
//        return info;
//    }

    /**  版本一：只能从token 里获取生成token的用户名
     * @AuthenticationPrincipal 注解可以获取生成token的用户名
//     * @param username
     * @return
     */
    @PostMapping("test")
    public String create(){
//        log.info("获取到username = {}",username);
        //查询价格
//        PriceInfo price = restTemplate.getForObject("http://localhost:9080/prices/"+info.getProductId(),PriceInfo.class);
//        log.info("price is "+price.getPrice());
        return "123456";
    }
}
